//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Priority
private alias 1 : PRIORITY_ACTIVE

private alias 114 : LEFTLIMIT

private alias Object[2].value0 : Object.Timer
private alias Object[2].value1 : Object.RightLimit
private alias Object[2].value2 : Object.ScrollPos

private alias Object[2].value5 : Object.LeftLight
private alias Object[2].value6 : Object.RightLight
private alias Object[2].value7 : Object.LeftDoor
private alias Object[2].value8 : Object.RightDoor

private alias Object[2].value9 : Object.LDoorSlide
private alias Object[2].value10 : Object.RDoorSlide

private alias Object[2].value11 : Object.OfficeAngle


private alias Object[2].value12: Object.MiddleDoor
private alias Object[2].value13 : Object.MDoorSlide


private alias Object[2].value15 : Object.UsingMask
private alias Object[2].value16 : Object.RButtonXPos
private alias Object[2].value17 : Object.RightButtonPos
private alias Object[2].value18 : Object.PowerTimer	
private alias Object[2].value19 : Object.TouchTimer	//ayo
private alias Object[2].value20 : Fan.FrameTimer
private alias Object[2].value21 : Fan.Frame

private alias Object[2].value22 : Object.RightSide
private alias Object[2].value23 : Object.Flash
private alias Object[2].value24 : Object.TableContainer

public table OfficeFlash
	32, 64, 96, 64
end table


private alias object[10].state : Freddy.State
private alias object[11].state : Bonnie.State
private alias object[12].state : Chica.State
private alias object[13].state : Foxy.State
private alias object[14].state : Endo.State	//he doesnt actually appear here but 
private alias object[15].state : GoldenFreddy.State	//he doesnt actually appear here but 
private alias object[16].state : Puppet.State	//he doesnt actually appear here but 
private alias object[17].state : Springtrap.State

private alias object[18].state : WitheredFreddy.State
private alias object[19].state : WitheredBonnie.State
private alias object[20].state : WitheredChica.State
private alias object[21].state : WitheredFoxy.State

private alias object[22].state : BalloonBoy.State
private alias object[23].state : JJ.State

private alias object[10].value4 : Freddy.AI
private alias object[11].value4 : Bonnie.AI
private alias object[12].value4 : Chica.AI
private alias object[13].value4 : Foxy.AI
private alias object[14].value4 : Endo.AI
private alias object[15].value4 : GoldenFreddy.AI
private alias object[16].value4 : Puppet.AI
private alias object[17].value4 : Springtrap.AI

private alias object[18].value4 : WitheredFreddy.AI
private alias object[19].value4 : WitheredBonnie.AI
private alias object[20].value4 : WitheredChica.AI
private alias object[21].value4 : WitheredFoxy.AI

private alias object[22].value4 : BalloonBoy.AI
private alias object[22].value4 : JJ.AI

public value LeftDoorClosed = 0;
public value RightDoorClosed = 0;
public value MiddleDoorClosed = 0;
public value OfficePower = 100;
public value CameraEnabled = 0;
public value PowerUsage = 1;
public value MaskMode = 0;
public value MaskEquipped = 0;
public value NightWon = 0;

public value LDoorLocked= 0;
public value RDoorLocked = 0;
public value MDoorLocked = 0;

public value LWindowScare= 0;
public value RWindowScare = 0;

public value PlayerJumpscared = 0;
public value OfficeScary = 0;

public value FlashlightOn = 0;

reserve function Office_LeftSide
reserve function Office_RightSide
reserve function Office_MiddleDoor

function Office_MiddleDoor
	DrawSpriteScreenXY(33, Object.ScrollPos, 60)	//door
	if Object.MiddleDoor == 1	//open
		DrawSpriteScreenXY(34, Object.ScrollPos, 60)	//door
		if Object.MDoorSlide < 51
			Object.MDoorSlide += 8
		else
			Object.MDoorSlide = 51
		end if
		DrawSpriteScreenXY(32, Object.ScrollPos, Object.MDoorSlide)	//door
	else
		if Object.MDoorSlide > 0
			Object.MDoorSlide -= 8
		else
			Object.MDoorSlide = 0
		end if	
		DrawSpriteScreenXY(32, Object.ScrollPos, Object.MDoorSlide)	//door

	end if	

	DrawSpriteScreenXY(31, Object.ScrollPos, -32)
end function

function Office_RightSide
	DrawSpriteScreenXY(18, Object.ScrollPos, 0)



	if Object.RightLight == 1
		if PlayerJumpscared == 1
			StopSfx(SfxName[Hum])
		else
			PlaySfx(SfxName[Hum], 1)	
		end if	
			
		//left door button
		DrawSpriteScreenXY(21, Object.ScrollPos, 0)

		DrawSpriteScreenXY(20, Object.ScrollPos, 0)
	end if	

	
//	if Freddy.State == 15
//		//FREDDY AT THE DOOR!!!
//		DrawSpriteScreenXY(26, Object.ScrollPos, 0)
//	end if



	if Object.RightDoor == 1	//open
		DrawSpriteScreenXY(19, Object.ScrollPos, 0) //left door button on
		if Object.RDoorSlide < 312
			Object.RDoorSlide += 18
		else
			Object.RDoorSlide = 312
		end if
		DrawSpriteScreenXY(23, Object.ScrollPos, Object.RDoorSlide)	//door
	else
		if Object.RDoorSlide > 0
			Object.RDoorSlide -= 18
		else
			Object.RDoorSlide = 0
		end if	
		DrawSpriteScreenXY(23, Object.ScrollPos, Object.RDoorSlide)	//door
	end if	

	//frame
	DrawSpriteScreenXY(22, Object.ScrollPos, 0)

end function

function Office_LeftSide

	//LEFT SIDE
	//left door button
	DrawSpriteScreenXY(12, Object.ScrollPos, 0)


	if Object.LeftLight == 1
		if PlayerJumpscared == 1
			StopSfx(SfxName[Hum])
		else
			PlaySfx(SfxName[Hum], 1)	
		end if		
		//left door button
		DrawSpriteScreenXY(15, Object.ScrollPos, 0)
		DrawSpriteScreenXY(14, Object.ScrollPos, 0)

	end if

	



	if Object.LeftDoor == 1	//open
		DrawSpriteScreenXY(13, Object.ScrollPos, 0) //left door button on
		if Object.LDoorSlide < 312
			Object.LDoorSlide += 18
		else
			Object.LDoorSlide = 312
		end if
		DrawSpriteScreenXY(17, Object.ScrollPos, Object.LDoorSlide)	//door
	else
		if Object.LDoorSlide > 0
			Object.LDoorSlide -= 18
		else
			Object.LDoorSlide = 0
		end if	
		DrawSpriteScreenXY(17, Object.ScrollPos, Object.LDoorSlide)	//door
	end if	

	//frame
	DrawSpriteScreenXY(16, Object.ScrollPos, 1)
end function

event ObjectMain

end event

event ObjectDraw


	CallFunction(Office_LeftSide)
	CallFunction(Office_RightSide)

	//office
	//i have no clue how this works its from CD Sonic code
	if OfficePower > 0
		Fan.Frame = 24
		Fan.FrameTimer += 128
		
		if Fan.FrameTimer > 239
			Fan.FrameTimer -= 240
			
			Fan.Frame++
			if Fan.Frame > 26
				Fan.Frame = 2
			end if
		end if
		DrawSpriteScreenXY(Fan.Frame, Object.ScrollPos, 0)
	end if

	
	Callfunction(Office_MiddleDoor)


//	temp0 = Object.ScrollPos
//	abs(temp0)
//	DrawNumbers(0, 32, 96, Object.TableContainer, 3, 8, 0)

end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Objects.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[7].Type = TypeName[OfficeDrawer]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[7].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[7].DrawOrder = 4

	Object[7].ScrollPos = 50

	Object[7].OfficeAngle = 0
	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	//SpriteFrame(-115, -1, 556, 253, 1, 1) // 10 - office og

	SpriteFrame(-115, -56, 682, 426, 1, 509) // 10 - office

	// 11 - mice
	SpriteFrame(0, 0, 12, 21, 1011, 1)


	//Left

	// 12 - Left Buttons
	SpriteFrame(-72, 96, 33, 66, 684, 509)	

	// 13 - 14, Door Lit, Light Lit
	SpriteFrame(-72, 96, 33, 34, 719, 509)	
	SpriteFrame(-72, 128, 33, 34, 719, 541)	//loght	

	//15 left door lit empty
	SpriteFrame(-34, -1, 134, 327, 684, 643)

	//16 left door empty frame
	SpriteFrame(-34, -40, 95, 369, 565, 139)	
	//17 left door
	SpriteFrame(-27, -302, 84, 314, 661, 194)	


	//Right

	// 18 - right Buttons
	SpriteFrame(490, 96, 33, 66, 684, 576)	

	// 19 - 20, Door Lit, Light Lit
	SpriteFrame(490, 96, 33, 34, 719, 576)	
	SpriteFrame(490, 128, 33, 34, 719, 608)	//loght	

	//21 right door lit empty
	SpriteFrame(352, -1, 134, 327, 819, 643)

	//22 right door empty frame
	SpriteFrame(391, -40, 95, 369, 831, 139)	
	//23 right door
	SpriteFrame(395, -302, 84, 314, 746, 194)	

	//24 fan animation frames
	SpriteFrame(218, 122, 40, 48, 794, 509)	
	//25 
	SpriteFrame(218, 122, 40, 48, 753, 509)		
	
	//fred 26 
	SpriteFrame(440, 67, 42, 126, 954, 643)		
	//bun 27
	SpriteFrame(-33, 46, 125, 188, 244, 1)		
	//jockey 28
	SpriteFrame(352, 41, 41, 118, 954, 770)	
	//golden gang 29
	SpriteFrame(140, 41, 166, 169, 370, 1)	

	//spring trap eyes
	SpriteFrame(225, 46, 62, 34, 621, 936)		//30

	//Middle Door Overlay
	SpriteFrame(225, 12, 62, 76, 437, 935)		//31

	//MiddleDoor
	SpriteFrame(226, 1, 61, 39, 499, 936)		//32

	//buton mid
	SpriteFrame(201, -2, 23, 23, 302, 936)		//33
	SpriteFrame(201, -2, 23, 23, 326, 936)		//34


	//flash ig? lol
	SpriteFrame(-128,-128,256,256,1,252)	//35
end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
